package srv;

import java.net.InetAddress;
import java.rmi.*;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import rmi.*;


public class Server {
    public void iniciar() {
    	try {
    		LocateRegistry.createRegistry(Registry.REGISTRY_PORT);
    		InterfazRemotaCPR ir_cpr = new ObjetoRemotoCPR();
    	    Naming.rebind ("//localhost/ObjetoRemotoCPR", ir_cpr);
    	    InterfazRemotaODV ir_odv = new ObjetoRemotoODV();
    	    Naming.rebind ("//localhost/ObjetoRemotoODV", ir_odv);
    	    verVinculos();
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    public void verVinculos() {
        try {
      	  String[] vinculos = Naming.list( "" );
     	  System.out.print("Vinculos disponibles en el servidor: ");
     	  System.out.println(InetAddress.getLocalHost().getHostAddress()); 
      	  for ( int i = 0; i < vinculos.length; i++ )
      		  System.out.println( vinculos[i] );
      	} catch (Exception e) { e.printStackTrace(); }
     }
    
    public void cerrar() {
		try {
			Naming.unbind("//localhost/ObjetoRemotoCPR");
			Naming.unbind("//localhost/ObjetoRemotoODV");
		} catch (Exception e) {
		}
    }
}
